<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-form-panel tb-slide-toggle stroked" [formGroup]="actionButtonConfigForm">
  <mat-expansion-panel class="tb-settings"
                       [expanded]="actionButtonConfigForm.get('enabled').value">
    <mat-expansion-panel-header class="fill-width flex flex-row flex-wrap">
      <mat-panel-title class="max-w-60% flex-full">
        <div tb-hint-tooltip-icon="{{ sliderHint }}" class="tb-form-row no-border no-padding">
          <mat-slide-toggle class="mat-slide flex items-stretch justify-center" formControlName="enabled" (click)="$event.stopPropagation()">
            {{ actionTitle }}
          </mat-slide-toggle>
        </div>
      </mat-panel-title>
    </mat-expansion-panel-header>
    <ng-template matExpansionPanelContent class="tb-extension-panel">
      <div class="flex flex-row xs:flex-col gt-xs:gap-2">
        <mat-form-field class="mat-block flex-1" *ngIf="!hideButtonText">
          <mat-label translate>notification.button-text</mat-label>
          <input matInput formControlName="text" required>
          <mat-error
            *ngIf="actionButtonConfigForm.get('text').hasError('required')">
            {{ 'notification.button-text-required' | translate }}
          </mat-error>
          <mat-error
            *ngIf="actionButtonConfigForm.get('text').hasError('maxlength')">
            {{ 'notification.button-text-max-length' | translate :
                {length: actionButtonConfigForm.get('text').getError('maxlength').requiredLength}
            }}
          </mat-error>
        </mat-form-field>
      </div>
      <div class="flex flex-row xs:flex-col gt-xs:gap-2">
        <mat-form-field class="max-w-30% flex-full xs:max-w-full">
          <mat-label translate>notification.action-type</mat-label>
          <mat-select formControlName="linkType">
            <mat-option *ngFor="let actionButtonLinkType of actionButtonLinkTypes"
                        [value]="actionButtonLinkType">
              {{ actionButtonLinkTypeTranslateMap.get(actionButtonLinkType) | translate }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <mat-form-field class="flex-1"
                        *ngIf="actionButtonConfigForm.get('linkType').value === actionButtonLinkType.LINK; else dashboardSelector">
          <mat-label translate>notification.link</mat-label>
          <input matInput formControlName="link" required>
          <mat-error
            *ngIf="actionButtonConfigForm.get('link').hasError('required')">
            {{ 'notification.link-required' | translate }}
          </mat-error>
        </mat-form-field>
        <ng-template #dashboardSelector>
          <tb-dashboard-autocomplete
            class="max-w-35% flex-full xs:max-w-full"
            required
            formControlName="dashboardId">
          </tb-dashboard-autocomplete>
          <tb-dashboard-state-autocomplete class="max-w-35% flex-full xs:max-w-full"
                                           [dashboardId]="actionButtonConfigForm.get('dashboardId').value"
                                           formControlName="dashboardState">
          </tb-dashboard-state-autocomplete>
        </ng-template>
      </div>
      <mat-slide-toggle formControlName="setEntityIdInState" class="toggle"
                        *ngIf="actionButtonConfigForm.get('linkType').value === actionButtonLinkType.DASHBOARD">
        {{ 'notification.set-entity-from-notification' | translate }}
      </mat-slide-toggle>
    </ng-template>
  </mat-expansion-panel>
</div>
